import unittest
from config import BASE_DIR
from api.login_api import LoginApi
from common.init_log import init_log_config
from common.read_json_data import build_data
from common.verify_assert_login import verify_login_assert


class TestLogin(unittest.TestCase):
    def test_login_ok(self):
        body = {"mobile": "13800000002", "password": "123456"}
        login_obj = LoginApi()
        response = login_obj.login(body)
        json_data = response.json()
        print(json_data)
        self.assertEqual(200, response.status_code)
        self.assertEqual(True, json_data['success'])
        self.assertEqual(10000, json_data['code'])
        self.assertIn("成功", json_data['message'])

    def test_user_err(self):
        body = {"mobile": "1380001232", "password": "123456"}
        login_obj = LoginApi()
        response = login_obj.login(body)
        json_data = response.json()
        print(json_data)
        self.assertEqual(200, response.status_code)
        self.assertEqual(False, json_data['success'])
        self.assertEqual(20001, json_data['code'])
        self.assertIn("错误", json_data['message'])

    def test_pwd_err(self):
        body = {"mobile": "13800000002", "password": "123456asd"}
        login_obj = LoginApi()
        response = login_obj.login(body)
        json_data = response.json()
        print(json_data)
        self.assertEqual(200, response.status_code)
        self.assertEqual(False, json_data['success'])
        self.assertEqual(20001, json_data['code'])
        self.assertIn("错误", json_data['message'])
